var table ;
layui.use(['form','jquery','table','laydate'],function() {
    var form = layui.form;
    var jquery = layui.jquery;
    table = layui.table;
    var laydate = layui.laydate;
    //时间选择器
    laydate.render({
        elem:'#test5'
    });

    $.ajax({
        url:'/UserFeedback/getUserFeedbackTable',
        methos:'post',
        dataType:'json',
        success:function (data) {
            tab(data);
        }
    })

    //表格渲染
    function tab(data) {
        table.render({
            id:"demo",
            elem:'#demo',
            width:1450,
            data:data.data,
            page:true,
            cols:[[
                {type:'checkbox'},
                {title:'序号', align:'center' ,width:70, templet:function (data) {
                        return data.LAY_INDEX;
                    }},
                {field:'userId',title:'用户账号',align:'center'},
                {field:'feedbackType',title:'意见反馈类型',align:'center',templet:function (data) {
                        var feedbackType;
                        if(data.feedbackType == 2){
                            feedbackType = "视频反馈";
                        }else if(data.feedbackType == 3){
                            feedbackType = "商品反馈";
                        }else{
                            feedbackType = "其他反馈";
                        }
                        return "<div>"+feedbackType+"</div>" ;
                    }},
                {field:'feedbackClassification',title:'意见分类',align:'center',templet:function (data) {
                        var feedbackClassification;
                        if(data.feedbackClassification == 2){
                            feedbackClassification = "很好";
                        }else if(data.feedbackClassification == 3){
                            feedbackClassification = "好"
                        }else if(data.feedbackClassification == 4){
                            feedbackClassification = "一般";
                        }else{
                            feedbackClassification = "差";
                        }
                        return "<div>"+feedbackClassification+"</div>";
                    }},
                {field:'createDate',title:'反馈时间',align:'center'},
                {field:'feedbackContent',title:'反馈内容',align:'center'},
                {field:'feedbackStatus',title:'操作',align:'center',templet:function(data){
                        var feedbackStatus;
                        if(data.feedbackStatus == 2){
                            feedbackStatus="已提交";
                        }else if(data.feedbackStatus == 3){
                            feedbackStatus="待审核";
                        }else if(data.feedbackStatus == 4){
                            feedbackStatus="受理";
                        }else if(feedbackStatus == 5){
                            feedbackStatus="未提交";
                        }else if (feedbackStatus == 6){
                            feedbackStatus="提交失败1"
                        }
                        return "<div class='operation' onclick='selectAccepted()'>"+feedbackStatus+"</div>"
                    }}
            ]]
        })
    }

    //刷新
    refresh = function refresh() {
        window.location.reload();
    }

    //重置
    reset = function reset(){
        $('input[name = title]').val("");
        $("select[name= feedbackType]").val('0');
        $("select[name= opinionClassification]").val('0');
    }

    //搜索
    KeywordSearch = function KeywordSearch() {

        var feedbackType = $("#feedbackType option:selected").val();
        var feedbackClassification = $("#opinionClassification option:selected").val();
        var createDate = $("input[name = createDate]").val();
        var userId = $("input[name = userAccount]").val();
        var selectData = {
            userId :  userId,
            feedbackType : feedbackType,
            feedbackClassification : feedbackClassification,
            createDate : createDate
        }

        $.ajax({
            url:'/UserFeedback/queryFeedback',
            dataType:'json',
            data:selectData,
            success:function (data) {
                tab(data);
            }
        })
    }

    //待审核
    ToBeReviewed = function ToBeReviewed(feedbackStatus){
        var feedbackStatus = $("#ToBeReviewed").text();
        $.ajax({
            url:'/UserFeedback/queryToBeReviewed',
            dataType:'json',
            data:feedbackStatus,
            success:function (data) {
                tab(data);
            }
        })
    }
    //已受理
    Accepted = function Accepted(feedbackStatus){
        var feedbackStatus = $("#Accepted").text();
        $.ajax({
            url:'/UserFeedback/queryAccepted',
            dataType:'json',
            data:feedbackStatus,
            success:function (data) {
                tab(data);
            }
        })
    }
    //个数
    getNum();
    function getNum() {
        //待审核个数
        $.ajax({
            url:'/UserFeedback/getToBeReviewedNum/',
            type:'post',
            dataType:'json',
            success:function (data) {
                $('.sele1 span').text(data.data);
            }
        })
        //已受理个数
        $.ajax({
            url:'/UserFeedback/getAcceptedNum/',
            type:'post',
            dataType:'json',
            success:function (data) {
                $('.sele2 span').text(data.data);
            }
        })
    }
    //图标样式
    $("#ToBeReviewed").on("click",function () {
        $(this).children(".sele1").addClass("selectStyle").parent().siblings().children(".sele2").removeClass("selectStyle");
    })
    $("#Accepted").on("click",function () {
        $(this).children(".sele2").addClass("selectStyle").parent().siblings().children(".sele1").removeClass("selectStyle");
    })

    //反馈弹出框
    selectAccepted = function  selectAccepted() {
        //获取选中行
        table.on('row(test)', function(obj){
            localStorage.setItem("fanKui",JSON.stringify(obj.data));
        });

        layer.open({
            type:2,
            content:"/FeedbackList/FeedbackFrame.html",
            area:['1080px','700px'],
            title:"受理用户反馈信息",
            end:function () {

            }
        });
    }

});